package com.maori.languageapp.fragments;

import java.io.File;

import com.maori.languageapp.R;
import com.maori.languageapp.Maori_Capture_Idiom;
import com.maori.languageapp.Maori_Capture_Phrase;
import com.maori.languageapp.Maori_Capture_Song;
import com.maori.languageapp.Maori_Capture_Story;
import com.maori.languageapp.Maori_Capture_Word;
import com.maori.languageapp.Maori_Categories;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;

public class Maori_Fragment_Capture extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		View view = inflater.inflate(R.layout.maori_fragment_capture, null);

		RelativeLayout captureWord = (RelativeLayout) view.findViewById(R.id.capture_word);
		RelativeLayout capturePhrase = (RelativeLayout) view.findViewById(R.id.capture_phrase);
		RelativeLayout captureStory = (RelativeLayout) view.findViewById(R.id.capture_story);
		RelativeLayout captureSong = (RelativeLayout) view.findViewById(R.id.capture_songs);
		RelativeLayout captureIdiom = (RelativeLayout) view.findViewById(R.id.capture_idioms);
	
		
		
		captureWord.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				//Intent i = new Intent(getActivity(), Maori_Capture_Word.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "200");
				i.putExtra("Capture_Type", "1");
				startActivity(i);
			}
		});
		
		capturePhrase.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				//Intent i = new Intent(getActivity(), Maori_Capture_Phrase.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "200");
				i.putExtra("Capture_Type", "2");
				startActivity(i);
			}
		});
		
		captureStory.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				//Intent i = new Intent(getActivity(), Maori_Capture_Story.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "200");
				i.putExtra("Capture_Type", "3");
				startActivity(i);
			}
		});
		
		captureSong.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				//Intent i = new Intent(getActivity(), Maori_Capture_Song.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "200");
				i.putExtra("Capture_Type", "4");
				startActivity(i);
			}
		});
		
		captureIdiom.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg) {
				//Intent i = new Intent(getActivity(), Maori_Capture_Idiom.class);
				Intent i = new Intent(getActivity(), Maori_Categories.class);
				i.putExtra("Display_Type", "200");
				i.putExtra("Capture_Type", "5");
				startActivity(i);
			}
		});

		return view;
	}

	
	//***********Memory Handling****************
	@Override
	public void onStop(){
	      super.onStop();
	   }

	   //Fires after the OnStop() state
	   @Override
	public void onDestroy() {
	      super.onDestroy();
	      try {
	         trimCache(this);
	      } catch (Exception e) {
	         // TODO Auto-generated catch block
	         e.printStackTrace();
	      }
	   }

	   public static void trimCache(Maori_Fragment_Capture maori_Fragment_Capture) {
	      try {
	         File dir = maori_Fragment_Capture.getCacheDir();
	         if (dir != null && dir.isDirectory()) {
	            deleteDir(dir);
	         }
	      } catch (Exception e) {
	         // TODO: handle exception
	      }
	   }

	   private File getCacheDir() {
		// TODO Auto-generated method stub
		return null;
	}


	public static boolean deleteDir(File dir) {
	      if (dir != null && dir.isDirectory()) {
	         String[] children = dir.list();
	         for (int i = 0; i < children.length; i++) {
	            boolean success = deleteDir(new File(dir, children[i]));
	            if (!success) {
	               return false;
	            }
	         }
	      }

	      // The directory is now empty so delete it
	      return dir.delete();
	   }

}
